
# 爬取标题名
import requests
import re
# url = 'https://spider.penpencode.com/'
# headers={
# "user-agent":
# 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
# }
# res = requests.get(url,headers=headers)
# print(res.text)
# text = re.findall(r'<div class="flex items-center justify-between font-bold"><span>(.*?)</span></div>',res.text)
# print(text)

# import
#爬取照片
l1 =[]
for i in range(1,5):
    url =f'https://spider.penpencode.com/douban/pic?page={i}'
    headers={
    "user-agent":
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
    }
    res =requests.get(url, headers=headers)
    img_res =re.findall(r'<p class="mb-10px"><img class="w-300px mx-auto block" src="(.*?)" alt=""></p>',res.text)
    for j in img_res:
        l1.append(j)
for j,s in enumerate(iterable=l1):
    res_img = requests.get(s)
    with open(f'static/img/img{j}.jpg','wb') as f:
        f.write(res_img.content)
        print(f'第{j}张')


# url = 'https://www.soutushenqi.com/image/feature?feature=%E7%94%B5%E8%84%91%E5%A3%81%E7%BA%B8'
# headers={
#     "user-agent":
#     'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36'
#     }
# res1 = requests.get(url, headers=headers)
# print(res1.text)